import { getToken } from '@/utils/auth'
import cache from '@/utils/cache'

const upload = async (File: any, type?: number) => {
    console.log('upload', File)
    return new Promise((resolve, reject) => {
        uni.uploadFile({
            url:
                (import.meta.env.VITE_IS_H5 === 'true'
                    ? '/api'
                    : import.meta.env.VITE_APP_BASE_URL) + '/admin/sys-file/upload',
            name: 'file',
            filePath: File,
            header: {
                Authorization: `Bearer ${getToken()}`,
                'CLIENT-TOC': 'Y',
                'TENANT-ID': cache.getTenant() || '',
                Language: cache.getLanguage().value
            },
            formData: {
                dir: '',
                type: type ? type : 10
            },
            success(res) {
                console.log(res)
                resolve(JSON.parse(res.data))
            },
            fail(e) {
                reject(e)
            }
        })
    })
}

export default upload
